home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
408_01
/
snews.c
< prev
next >
Wrap
Text File
|
1993-08-06
|
44KB
|
1,565 lines
/*
SNEWS 1.91
snews - a simple threaded news reader
Copyright (C) 1991 John McCombs, Christchurch, NEW ZEALAND
john@ahuriri.gen.nz
PO Box 2708, Christchurch, NEW ZEALAND
Modifications copyright (C) 1993 Daniel Fandrich
<dan@fch.wimsey.bc.ca> or CompuServe 72365,306
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 1, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See the file COPYING, which contains a copy of the GNU General
Public License.
Source is formatted with a tab size of 4.
*/
#include "defs.h"
#include "snews.h"
#include "pccharst.h"
#include "getopt.h"
#include <alloc.h>
#include <ctype.h>
#include <process.h>
unsigned _stklen = 8192; /* default 4k stack can give problems */
INFO my_stuff;
/*------------------------------- main --------------------------------*/
int main(int argc, char *argv[])
{
ACTIVE *gp, *head;
int done, option;
int verbose = 1, errflag = 0;
signal(SIGINT, sig_break); /* turn control-break off */
if (getenv("BIOSVIDEO") ||
(getenv("TERM") && (stricmp(getenv("TERM"), "pcbios") == 0)))
directvideo = 0;
select_code_page();
while ((option = getopt(argc, argv, "bqv?")) != -1)
switch (option) {
case 'b': /* bios video output */
directvideo = 0;
break;
case 'q': /* quiet mode */
verbose = 0;
break;
case 'v': /* verbose mode */
++verbose;
break;
case '?': /* display help */
++errflag;
break;
};
if ((argc > 1) && (argv[1][0] == '/'))
++errflag;
if (verbose)
printf(VERSION "\n"
"type snews -? for usage\n\n");
if ((verbose >= 2) || errflag)
printf(
"Copyright (C) 1991 John McCombs\n"
"Copyright (C) 1992 Michael Studte/John Dennis (Shinohara Industries)\n"
"Copyright (C) 1992 Kai Uwe Rommel\n"
"Copyright (C) 1993 Daniel Fandrich\n\n"
"SNEWS comes with ABSOLUTELY NO WARRANTY.\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions; see the file COPYING for details.\n\n");
if (errflag) {
printf(
"usage: snews [-q] [-v] [-b]\n"
" -q set quiet mode\n"
" -v set verbose mode\n"
" -b use BIOS for video output\n"
);
return 2;
}
if (verbose)
printf("loading config... ");
if (load_stuff()) {
if (verbose)
printf("loading active... ");
head = load_active_file();
if (verbose)
printf("loading read list... ");
load_read_list();
if (verbose)
printf("loading history... ");
load_history_list();
done = FALSE;
gp = NULL;
while (!done) {
if ((gp = select_group(head, gp)) != NULL) {
done |= read_group(gp);
} else {
done = TRUE;
}
}
clrscr();
free_hist_list();
if (verbose)
printf("writing read list... ");
save_read_list();
if (verbose)
printf("done\n");
close_active_file();
} else {
fprintf(stderr, "Couldn't find neccessary item in the .rc files\n");
return 2;
}
return 0;
}
/*-------------------------- find which group to read -----------------------*/
ACTIVE *select_group(ACTIVE *head, ACTIVE *current)
{
/*
* Present the list of groups, and allow him to move up and down with
* the arrow and PgUp and PgDn keys. 'h' for help, -/+ for searches
*/
ACTIVE *top; /* newsgroup at the top of the page */
ACTIVE *this; /* current newsgroup */
ACTIVE *tmp_ng;
enum exit_codes exit_code; /* why we are exiting the loop */
char sub_tmp[80];
int i, j, articles, unread;
this = (current == NULL) ? head : current;
top = head;
exit_code = EX_CONT;
show_groups(&top, this, TRUE);
while (exit_code == EX_CONT) {
switch (get_any_key()) {
case Fn1 :
case '?' :
case 'h' :
show_help(HELP_GROUP);
show_groups(&top, this, TRUE);
break;
case Fn2 :
show_values();
show_groups(&top, this, TRUE);
break;
case UP_ARR :
if (this->last != NULL) this = this->last;
break;
case DN_ARR :
if (this->next != NULL) this = this->next;
break;
case PGUP :
for (i = 0; i < PAGE_LENGTH; i++) {
if (this->last == NULL) break;
this = this->last;
}
break;
case PGDN :
for (i = 0; i < PAGE_LENGTH; i++) {
if (this->next == NULL) break;
this = this->next;
}
break;
case '1' :
case HOME :
top = this = head;
show_groups(&top, this, TRUE);
break;
case '$' :
case END :
this = head;
while (this->next != NULL)
this = this->next;
show_groups(&top, this, TRUE);
break;
case '/' :
case '+' :
this = search_groups(this);
break;
case 'p' :
strcpy(sub_tmp, "");
post(NULL, this->group, sub_tmp);
show_groups(&top, this, TRUE);
break;
case 'c' :
mark_group_as_read(this);
show_groups(&top, this, TRUE);
break;
case ' ' :
case 'n' :
case TAB :
tmp_ng = this->next;
unread = 0;
while (tmp_ng != NULL) {
articles = (int) (tmp_ng->hi_num - tmp_ng->lo_num);
for (j = 0; j < articles; j++) {
if ( *((tmp_ng->read_list)+j) == FALSE)
unread++;
}
if (unread > 0) break;
tmp_ng = tmp_ng->next;
}
if (unread > 0) {
this = tmp_ng;
} else {
message("-- No more articles to read --");
}
break;
case '!' :
textbackground(BLACK); textcolor(LIGHTGRAY);
cprintf("\r\n");
spawnl(P_WAIT, getenv("COMSPEC"), getenv("COMSPEC"), NULL);
show_groups(&top, this, TRUE);
break;
case ENTER :
exit_code = EX_DONE;
break;
case 'q' :
case ESCAPE :
exit_code = EX_QUIT;
break;
};
if (exit_code == EX_CONT)
show_groups(&top, this, FALSE);
}
if (exit_code == EX_DONE)
return(this);
else
return(NULL);
}
/*---------------------------- help screen ----------------------------------*/
void show_help(int h)
{
char *type[] = {"New Group", "Thread", "Article"};
textbackground(helpb); textcolor(helpf);
clrscr();
textbackground(headb); textcolor(headf);
clreol();
cprintf(" %s Help (%s)\r\n", type[h], VERSION);
clreol();
textbackground(helpb); textcolor(helpf);
switch (h) {
case HELP_GROUP :
cprintf("\r\n\r\n");
cprintf(" LIST NEWSGROUPS CHOOSING NEWSGROUPS\r\n\r\n");
cprintf(" PgUp move display up one page